package cn.xaut.周赛.m227;

/**
 * 5672. 检查数组是否经排序和轮转得到
 */
public class demo5672 {

    public boolean check(int[] nums) {

        int len = nums.length;
        for (int x = 0; x < len; x++) {
            int[] a = new int[len];
            for (int i = 0; i < len; i++)
                a[i] = nums[(i + x) % len];
            boolean flag = true;
            for (int i = 1; i < len; i++) {
                if (a[i] < a[i - 1]) {
                    flag = false;
                    break;
                }
            }
            if (flag)
                return true;
        }

        return false;
    }

    public static void main(String[] args) {

        System.out.println(new demo5672().check(new int[]{3, 4, 5, 1, 2})); // true
        System.out.println(new demo5672().check(new int[]{2, 1, 3, 4}));    // false
        System.out.println(new demo5672().check(new int[]{1, 2, 3}));       // true
        System.out.println(new demo5672().check(new int[]{1, 1, 1}));       // true
        System.out.println(new demo5672().check(new int[]{2, 1}));          // true
    }
}
